--- title: IO keywords: fastai sidebar: home_sidebar summary: "Tools related to input/output" description: "Tools related to input/output" nb_path: "notebooks/03_io.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

class PDSReader[source]

PDSReader(datapath:Union[str, Path])

Class to support the correct binary reading of the PDS DAT files.

This class focuses on reading the DAT files. For a more complete reader, look below at the UVPDS

{% endraw %} {% raw %}
{% endraw %} {% raw %}
pid = "FUV2005_172_03_35"
{% endraw %} {% raw %}
pds = PDSReader(get_data_path(pid))
{% endraw %} {% raw %}
pds.data.shape
(1024, 60, 164)
{% endraw %} {% raw %}
pds.band_range
[0, 1024]
{% endraw %} {% raw %}
pds.line_range
[2, 62]
{% endraw %} {% raw %}

class UVPDS[source]

UVPDS(uvis_id:str, skip_download:bool=False)

Class to manage a PDS product.

One PDS product has a PRODUCT_ID like FUV2003_358_05_59 and hence provides either EUV or FUV data.

If the calibration matrix PDS file is available, the wavelengths are being read from the calmatrix label file, correctly binned for BAND_BIN, if required, otherwise default wavelengths are being assumed, as given per UVIS manual.

See UVISOBS for a class that manages all data related to one observation, i.e. both EUV and FUV, and also HDAC and HSP data.

{% endraw %} {% raw %}
{% endraw %} {% raw %}
uv = UVPDS(pid)
{% endraw %} {% raw %}
uv.xarray
<xarray.DataArray 'FUV2005_172_03_35' (spectral: 1024, spatial: 60, samples: 164)>
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Coordinates:
  * spectral  (spectral) float64 111.5 111.6 111.7 111.8 ... 191.1 191.2 191.3
  * spatial   (spatial) int64 2 3 4 5 6 7 8 9 10 ... 53 54 55 56 57 58 59 60 61
  * samples   (samples) int64 1 2 3 4 5 6 7 8 ... 158 159 160 161 162 163 164
Attributes:
    units:                 Counts
    long_name:             FUV raw data
    n_bands:               1024
    integration_duration:  Quantity(value=240.0, units='SECOND')
{% endraw %} {% raw %}
uv.calibrated
<xarray.DataArray 'FUV2005_172_03_35' (spectral: 1024, spatial: 60, samples: 164)>
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0
Coordinates:
  * spectral  (spectral) float64 111.5 111.6 111.7 111.8 ... 191.1 191.2 191.3
  * spatial   (spatial) int64 2 3 4 5 6 7 8 9 10 ... 53 54 55 56 57 58 59 60 61
  * samples   (samples) int64 1 2 3 4 5 6 7 8 ... 158 159 160 161 162 163 164
Attributes:
    units:                 kiloRayleighs
    long_name:             FUV calibrated data
    n_bands:               1024
    integration_duration:  Quantity(value=240.0, units='SECOND')
{% endraw %} {% raw %}
uv.wavelengths
$[111.535,~111.613,~111.69,~\dots,~191.131,~191.209,~191.287] \; \mathrm{nm}$
{% endraw %} {% raw %}
uv.pid
'FUV2005_172_03_35'
{% endraw %} {% raw %}
uv.integration_duration
Quantity(value=240.0, units='SECOND')
{% endraw %} {% raw %}
uv.file_id
'FUV2005_172_03_35'
{% endraw %} {% raw %}
uv.default_wave_min, uv.default_wave_max
(<Quantity 111.5 nm>, <Quantity 190. nm>)
{% endraw %} {% raw %}
uv.n_bands
1024
{% endraw %} {% raw %}
uv.n_integrations
164
{% endraw %} {% raw %}
uv.pds.band_range, uv.pds.line_range
([0, 1024], [2, 62])
{% endraw %} {% raw %}

UVPDS.plot[source]

UVPDS.plot(precise:bool=False, percentiles:tuple=(0.5, 99.5), clim:tuple=None, cmap:str='viridis', calibrated=False)

Create default hvplot for the data.

Due to non-equidistant wavelengths, one should use the quadmesh plot, but that is less performant than a constant raster and creates an annoying aliasing structure when zoomed out (however correct, though).

I am investigating if that aliasing can be avoided, it might come from gridlines. So I leave it to the user to switch to the raster plot using the precise switch.

{% endraw %} {% raw %}
uv.plot()
{% endraw %} {% raw %}
uv.plot(precise=True)
{% endraw %} {% raw %}
(uv.plot().opts(axiswise=False) + uv.plot(precise=True)).cols(1)
{% endraw %} {% raw %}
uv.plot(calibrated=True)
{% endraw %} {% raw %}

class UVISObs[source]

UVISObs(pid_or_timestring)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
pds = UVISObs("FUV2005_172_03_35")
{% endraw %} {% raw %}
pds.timestring
'2005_172_03_35'
{% endraw %} {% raw %}
pds.euv
<__main__.UVPDS at 0x7f2ac82f7130>
{% endraw %} {% raw %}
pds.euv.wavelengths
$[56.1229,~56.1833,~56.2438,~\dots,~118.033,~118.093,~118.154] \; \mathrm{nm}$
{% endraw %} {% raw %}
pds.fuv.wavelengths
$[111.535,~111.613,~111.69,~\dots,~191.131,~191.209,~191.287] \; \mathrm{nm}$
{% endraw %}

Examples from the UVIS User's guide

Get the current user guide PDF by using get_user_guide()

{% raw %}
get_user_guide()
Path('/home/maye/big_drive/planetary_data/missions/cassini/uvis/uvis_user_guide.pdf')
{% endraw %} {% raw %}
pid = "FUV2005_172_03_35"
{% endraw %} {% raw %}
data = UVPDS(pid)
{% endraw %} {% raw %}
arr = data.xarray
{% endraw %} {% raw %}
arr.sum(["spatial", "samples"]).hvplot(ylim=(0, 5e5), xlim=(100, 200), title="Total counts")
{% endraw %} {% raw %}
pid = "FUV2004_163_19_22"
{% endraw %} {% raw %}
data = UVPDS(pid)
arr = data.xarray
{% endraw %} {% raw %}
summed = arr.sel(samples=15, drop=True).sum(["spatial"]) / (64 * 30)
{% endraw %} {% raw %}
s = summed.to_pandas()
{% endraw %} {% raw %}
import hvplot.pandas
{% endraw %} {% raw %}
kwargs = {"ylim": (0, 0.02), "xlim": (110, 190), "width": 500}
{% endraw %} {% raw %}
blackman = s.rolling(window=14, win_type="blackmanharris").mean().hvplot(**kwargs, label='blackmanharris')
blackman
{% endraw %} {% raw %}
gaussian = s.rolling(window=10, win_type="gaussian").mean(std=3).hvplot(**kwargs, label="gaussian")
gaussian
{% endraw %} {% raw %}
gaussian * blackman
{% endraw %} {% raw %}
pid = "FUV2005_195_19_52"
{% endraw %} {% raw %}
data = UVPDS(pid)
arr = data.xarray
{% endraw %} {% raw %}
data.shape
(512, 25, 71)
{% endraw %} {% raw %}
s16 = arr.sel(samples=16).sum("spatial")
s32 = arr.sel(samples=32).sum("spatial")
{% endraw %} {% raw %}
ratio = s32 / s16
{% endraw %} {% raw %}
(
    s16.hvplot(ylim=(0, 400), title="Sample #16")
    + s32.hvplot(ylim=(0, 400), title="Sample #32")
    + ratio.hvplot(title="Ratio", shared_axes=False)
).cols(1)
{% endraw %} {% raw %}
arr.sum(["spatial", "samples"]).hvplot()
{% endraw %} {% raw %}
pid = "EUV2002_198_03_26_54_UVIS_C33ST_SPICARAST002_PRIME"
pid = "FUV2005_195_19_52"
{% endraw %}

NetCDF readers

The NetCDF readers can be used for the UVIS team internally distributed netCDF files.

{% raw %}

class UVIS_NetCDF[source]

UVIS_NetCDF(fname, freq)

{% endraw %} {% raw %}
{% endraw %} {% raw %}

class HSP[source]

HSP(fname, freq) :: UVIS_NetCDF

Class for reading NetCDF UVIS HSP data files.

Parameters

fname: {str, pathlib.Path} Path to file to read freq: str String indicating the sampling frequency, e.g. '1ms', '2ms'

Examples

hsp = hsp('path', '1ms')

{% endraw %} {% raw %}
{% endraw %} {% raw %}

class FUV_CDF[source]

FUV_CDF(fname, freq='1s') :: UVIS_NetCDF

FUV NetCDF reader class.

Parameters

fname: str or pathlib.Path Path to file to read freq: str String indicating the sampling frequency, e.g. '1s', '2s'

Examples

fuv = FUV_CDF('path', '1s')

{% endraw %} {% raw %}
{% endraw %} {% raw %}

class EUV_CDF[source]

EUV_CDF(fname:Union[str, Path], freq:str='1s') :: UVIS_NetCDF

EUV NetCDF reader class.

{% endraw %} {% raw %}
{% endraw %}